#Copyright (c) 2025, Alibaba Cloud and its affiliates;
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.



import logging
import logging.handlers as handlers

class Singleton(object):
  def __new__(cls, *args, **kw):
    if not hasattr(cls, '_instance'):
      orig = super(Singleton, cls)
      cls._instance = orig.__new__(cls)
    return cls._instance

class Logger(Singleton):
  def __init__(self, file_path = '/usr/local/fce/logs/fceutil.log', log_level = 'DEBUG', name = 'FceUtil') -> None:
    self.logger = logging.getLogger(name)
    self.logger.setLevel(log_level)
    fmt = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
    formatter = logging.Formatter(fmt)
    handler = handlers.RotatingFileHandler(file_path, maxBytes = 1024*1024*10, backupCount = 30)
    handler.setFormatter(formatter)
    self.logger.addHandler(handler)
    self.logger.setLevel(log_level)
    self.logger.propagate = True
'''
  def critical(self, msg, *args, **kwargs):
      self.logger.critical(msg, *args, **kwargs)

  def exception(self, msg, *args, **kwargs):
      self.logger.exception(msg, *args, **kwargs)

  def error(self, msg, *args, **kwargs):
      self.logger.error(msg, *args, **kwargs)

  def warning(self, msg, *args, **kwargs):
      self.logger.warning(msg, *args, **kwargs)

  def info(self, msg, *args, **kwargs):
      self.logger.info(msg, *args, **kwargs)

  def debug(self, msg, *args, **kwargs):
      self.logger.debug(msg, *args, **kwargs)
'''
  
g_logger = Logger(log_level='DEBUG')

